/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[][]}
 */
 var levelOrder = function(root) {
    let res = [],
        queue = [];
    if(!root) return res
    queue.push(root)
    while(queue.length!==0){
        //记录当前节点数 为了全部shfit 出去
       let length =queue.length
       //记录当前层的节点的值
       let curr =[]
       for(let i=0;i<length;i++){
            let node = queue.shift()
            curr.push(node.val)
            //存放下一层结点
            for(let item of node.children){
                item&&queue.push(item);
            }
       }
       res.push(curr)
    }
    return res
};